package com.hs.hlw.credit.system.web.controller.api;

import com.hs.hlw.credit.system.business.dto.ResponseDto;
import com.hs.hlw.credit.system.business.service.TableService;
import com.hs.hlw.credit.system.data.DataUtils;
import com.hs.hlw.credit.system.data.mybatis.Pageable;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * TableController
 * @author zhb
 * @date 2018/11/19
 */
@RestController
@RequestMapping("/api/table")
public class TableController {
    private @Autowired TableService tableService;

    @GetMapping(path = "getTableListByDataSource")
    @ApiOperation(value = "获取数据库表列表", notes = "获取数据库表列表")
    public ResponseDto getTableListByDataSource(@RequestParam @ApiParam(value = "数据源ID", required = true) Integer dataSourceId,
                            @RequestParam(required = false, defaultValue = "1") @ApiParam(value = "查询页码", defaultValue = "1") Integer page,
                            @RequestParam(required = false, defaultValue = "10") @ApiParam(value = "每页数据条数", required = true, defaultValue = "10") Integer size,
                            @RequestParam(required = false, defaultValue = "xmlid") @ApiParam(value = "排序字段（多个用逗号隔开）", defaultValue = "xmlid") String orderField,
                            @RequestParam(required = false, defaultValue = "asc") @ApiParam(value = "排序规则（asc:升序，desc:降序，多个用逗号隔开）", defaultValue = "asc") String direction) {

        Pageable pageable = DataUtils.pageable(page, size, orderField, direction);
        pageable.addParam("dataSourceId", dataSourceId);

        return tableService.page(pageable);
    }
}